package main;

import java.util.Arrays;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import cn.edu.seu.io.util.IO;
import cn.edu.seu.java.parser.BatchedASTParser;
import cn.edu.seu.java.util.ASTNodeUtil;


public class MainTest {
	public static void main(String[] arg) {
		IO.clear();
		List<String> projPaths = Arrays.asList("E:\\idealzhang\\JAVA\\JAVA\\ASTParser");
		for (String versionPath : projPaths) {
			BatchedASTParser parser = new BatchedASTParser(versionPath);
			List<CompilationUnit> units = parser.generateCompilationUnits();
			//System.out.println(versionPath);

			for (CompilationUnit unit : units) {
				String sourceFilePath = (String) unit.getProperty("sourceFilePath");
				List<TypeDeclaration> types = ASTNodeUtil.getTopTypeDeclarations(unit);
				for (TypeDeclaration type : types) {
					for (MethodDeclaration md : type.getMethods()) {
						md.accept(new ASTVisitor() {
							@Override
							public boolean visit(MethodInvocation node) {
								String callerFullName = ASTNodeUtil.getFullyQualifiedName(md);
								String calleeFullName = ASTNodeUtil.getFullyQualifedName(node);
								
								if (calleeFullName.length() > 0) {
									System.out.println(sourceFilePath);
									System.out.println(callerFullName + "-->" + calleeFullName);
									System.out.println("Line:" + ASTNodeUtil.getStartLine(node));
									System.out.println(node.toString());
									System.out.println();
								}
								
								return false;
							}
						});
					}
				}
			}
		}
	}
}
